

#include "logtracer_udp.h"
#include "log.h"
#include <iostream>
#include <sstream>
#include "tools/socket.h"
#include <stdlib.h>

namespace logging {

static tools::CSocket *  sockU = NULL;

LogTracerUdp::LogTracerUdp()
{
    if (!sockU)
        sockU = new tools::CSocket(tools::CSocket::eSocketType_UDP);
    sockU->Create();
    sockU->SetRemoteIP("127.0.0.1");
    sockU->SetRemotePort(10234);
}

LogTracerUdp::~LogTracerUdp()
{
}

void LogTracerUdp::Output(const LogMessage::RawMessage& message)
{
    std::stringstream    oss;
    oss << message.timestamp_ 
        << " [DEBUG] "
        << "[" 
        << message.file_ 
        << ':' 
        << message.func_
        << ':'
        << message.line_
        << "] "
        << message.text_;
    if (sockU)
        sockU->Send(oss.str().c_str(), oss.str().length());
}


}

